// src/boot/latlng.plugin.ts
import { registerPlugin } from '@capacitor/core'

export interface LatLngPlugin {
  // 核心方法
  startListening(): Promise<void>
  stopListening(): Promise<void>

  // 权限管理
  checkPermissions(): Promise<{ location: 'granted' | 'denied' }>
  requestPermissions(): Promise<{ location: 'granted' | 'denied' }>

  // 事件监听
  addListener(
    eventName: 'positionUpdate',
    listenerFunc: (data: { lat: number; lng: number; accuracy: number; timestamp: number }) => void,
  ): Promise<{ remove: () => void }>

  addListener(
    eventName: 'nmeaUpdate',
    listenerFunc: (data: { raw: string; timestamp: number }) => void,
  ): Promise<{ remove: () => void }>
}

declare module '@capacitor/core' {
  interface PluginRegistry {
    LatLng: LatLngPlugin
  }
}

export const LatLng = registerPlugin<LatLngPlugin>('LatLng')
